<template>
  <el-container class="home">
    <el-header>
      <div class="fl">
        <img src="../assets/heima.png" alt="" />电商后台管理系统
      </div>
      <div class="fr">
        <el-button type="primary">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="toggleFlag ? '64px' : '200px'">
        <div class="toogle_bar" @click="toggleBar">|||</div>

        <el-menu
          class="el-menu-vertical-demo"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse="toggleFlag"
          :collapse-transition="false"
          :router="true"
          :default-active="activePath"
        >
          <!-- 第1层 -->
          <el-submenu
            :index="item1.id + ''"
            v-for="item1 in menuList"
            :key="item1.id"
          >
            <template slot="title">
              <i :class="classObj[item1.id]"></i>
              <span>{{ item1.authName }}</span>
            </template>
            <!-- 第2层 -->
            <!-- <el-menu-item-group> -->
            <el-menu-item
              :index="item2.path"
              v-for="item2 in item1.children"
              :key="item2.id"
              @click="savePath(item2.path)"
            >
              <i class="el-icon-menu"> {{ item2.authName }}</i>
            </el-menu-item>
            <!-- </el-menu-item-group> -->
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menuList: [],
      classObj: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      toggleFlag: false,
      activePath: "",
    };
  },
  created() {
    this.getMenuList();
    this.activePath = localStorage.getItem("path");
  },
  methods: {
    async getMenuList() {
      const { data: res } = await this.$axios.get("menus");
      // console.log(res);
      this.menuList = res.data;
    },
    toggleBar() {
      this.toggleFlag = !this.toggleFlag;
    },
    savePath(path) {
      // console.log(path);
      localStorage.setItem("path", path);
      this.activePath = path;
    },
  },
};
</script>

<style lang="less" scoped>
.home {
  height: 100%;
  .el-header {
    padding: 0;
    background-color: #373d41;
    font-size: 20px;
    color: #fff;
    img {
      vertical-align: middle;
      padding-right: 10px;
    }
    .fl {
      float: left;
    }
    .fr {
      float: right;
      padding-right: 20px;
      margin-top: -3px;
    }
  }
  .el-icon-menu {
    font-size: 14px;
    margin-right: 5px;
  }
  .iconfont {
    font-size: 14px;
    margin-right: 5px;
  }
  .toogle_bar {
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
  .el-menu {
    border: none;
  }
}
</style>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  background-color: #373d41;
  color: #333;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
  /* height: 100%; */
}

/* .el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
} */
</style>